package com.hnevc.xiewenguang;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;

/**
 * 【IO流】
 * 字节流
 * InputStream 输入流 读  ->FlieInputStream
 * OutputStream 输出流 写 -> FlieOUTputStream
 *
 * 字符流
 *
 */
public class Example01 {
    /*


    对于文件使用字节流进行读写操作

     */
    public static void main(String[] args) {
        //写
        try {
            FileOutputStream out = new FileOutputStream("text.txt");
            String str = "姓名 + 学号";
            byte[] b = str.getBytes();   //获取字符串内容转换为字节数组
            out.write(b);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //读
        try {
            FileInputStream in = new FileInputStream("HelloWorld.txt");
            int b = 0;
            while (true) {
                b = in.read();
                if (b == -1) {
                    break;
                }
                System.out.println(b);
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
